package com.fenghongzhang.day004;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;

public class Main4Activity extends AppCompatActivity {

    private EditText edit;
    private Button btn;
    private FrameLayout fl4;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main4);

        edit = (EditText) findViewById(R.id.edit);
        btn = (Button) findViewById(R.id.btn);
        fl4 = (FrameLayout) findViewById(R.id.fl4);


        //加载fg
        FragmentManager supportFragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = supportFragmentManager.beginTransaction();
        BlankFragment4 blankFragment4 = new BlankFragment4();
        fragmentTransaction.add(R.id.fl4, blankFragment4);
        fragmentTransaction.commit();




        //用setArguments 和get 换换值

        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String s = edit.getText().toString();

                //用setArgements  和 get
                BlankFragment4 blankFragment4 = new BlankFragment4();
                Bundle bundle = new Bundle();
                bundle.putString("key",s);
                blankFragment4.setArguments(bundle);
                FragmentManager supportFragmentManager1 = getSupportFragmentManager();
                FragmentTransaction fragmentTransaction1 = supportFragmentManager1.beginTransaction();
                fragmentTransaction1.replace(R.id.fl4,blankFragment4);
                fragmentTransaction1.commit();

            }
        });

    }
}
